#ifndef _LOGCI_LAMPMODEL_H_
#define _LOGCI_LAMPMODEL_H_

#include "PlatformTypes.h"
#include "F3LampInterfaces.h"
#include "FrntTurnLampSnapshot.h"

#define LobeamDefaultPWM 100.0f
#define HibeamDefaultPWM 100.0f

extern bool IsLampTurnOn(OnOffFlag flag);

// dev support, maybe delete later
typedef struct LeTurnLamp_TL_EN_FaultFlag
{
    bool    isFault_;
    // if fault but, TL_EN recovery as normal, and TL_EN count > 5, then troubleshoot
    uint8_t TL_EN_recoveryCount_;
}LeTurnLamp_TL_EN_FaultFlag;
void buildLeTurnLamp_TL_EN_FaultFlag(LeTurnLamp_TL_EN_FaultFlag* lastFlag, LeTurnLamp_TL_EN_FaultFlag* newFlag);

typedef enum DayTimeAndPosnLampBrightness
{
    DayTimeAndPosnLamp_Off          = 0x00,
    DayTimeAndPosnLamp_DayTime      = 0x01,
    DayTimeAndPosnLamp_PosnNight    = 0x02, //Posn lamp brightness level1
    DayTimeAndPosnLamp_Posn1        = 0x04, //Posn lamp brightness level2
    DayTimeAndPosnLamp_Posn2        = 0x05, //Posn lamp brightness level3(brightest)
} DayTimeAndPosnLampBrightness;

typedef struct DayTimeAndPosnLampModel
{
    OnOffFlag   onOffStatus_;
    uint32_t    mask_;  //1111 0000... High 4 bit lamp turn on
    float       pwm_;
    DiagFlag    FLDaytimeLampFlt_;
    DiagFlag    LeFrntPosnLampFlt_;

    FrntTurnLampSnapshot    snapshot_;
}DayTimeAndPosnLampModel;


typedef struct DlpModel
{
    bool            isLM3409_EN_Enable_;
    uint8_t         DO_S32K_SL3409_PWM_;//1 ~ 99
    bool            isDLP_LED1_And_DLP_LED2_Enable_;
    ProjectionAngle angle_;
}DlpModel;

typedef struct HiBeamModel
{
    OnOffFlag   onOffStatus_;
    DiagFlag    LeHiBeamFlt_;
}HiBeamModel;

typedef struct LoBeamModel
{
    OnOffFlag onOffStatus_;
    float     pwm_;
    DiagFlag  LeLoBeamFlt_;
}LoBeamModel;

typedef struct LeftFrontTurnLampModel
{
    OnOffFlag   onOffStatus_;
    bool        is_TL_Flow_Enable_;
    float       pwm_;
    uint32_t    mask;  //1111 0000... High 4 bit lamp turn on
    DiagFlag    LeFrntTurnLampFlt_;
    LeTurnLamp_TL_EN_FaultFlag  TL_EN_FaultFlag_;
}LeftFrontTurnLampModel;


typedef struct PO2_LEDModel
{
    OnOffFlag onOffStatus_;
}PO2_LEDModel;

typedef struct StarrySkyModel
{
    OnOffFlag   onOffStatus_;
    float       pwm_;
    uint32_t    mask_;  //1111 0000... High 4 bit lamp turn on
}StarrySkyModel;

typedef struct CornerLampModel
{
    OnOffFlag onOffStatus_;
    uint8_t   CL_SW_PWM_;
    bool      isDiagIssue_;
}CornerLampModel;

typedef struct RibbonModel
{
    RibbonEffectShowSt  frntRibbonLampEffectShowSt_;
    RibbonEffectSel     frntRibbonLampEffectSt_;
    RibbonEffectShowSt  loBeamEffectShowSt_;
    RibbonEffectSel     loBeamEffectSt_;
} RibbonModel;

typedef struct LampModel
{
    DayTimeAndPosnLampModel  dayTimeAndPosnLampModel_;
    DlpModel                 dlpModel_;
    HiBeamModel              hiBeamModel_;
    LeftFrontTurnLampModel   leftFrontTurnLampModel_;
    LoBeamModel              loBeamModel_;
    PO2_LEDModel             po2LedModel_;
    StarrySkyModel           StarrySkyModel_;
    CornerLampModel          CornerLampModel_;
    RibbonModel              ribbonModel_;
} LampModel;

typedef enum RibbonAnimationModelType
{
    Default          = 0x00,
    Init             = 0x01,
    Pause            = 0x02,
    Hold             = 0x03,
    Repeat           = 0x04,
    LeTurnLampOccupy = 0x05,
} RibbonAnimationModelType;

typedef struct RibbonAnimationModel
{
    RibbonAnimationModelType lobeamMode_;
    RibbonAnimationModelType lastLobeamMode_;
    RibbonAnimationModelType posnMode_;
    RibbonAnimationModelType lastPosnMode_;
} RibbonAnimationModel;

typedef enum SystemState
{
    System_Init = 0x00,
    System_Weakup = 0x01,
    System_Sleep = 0x02,
} SystemState;

/**
 * @brief record sleep weakup mode
 *  lampsOnOffMask_ : remember lamps on off state
 *                    bit0 : daytime and posn
 *                    bit1 : dlp
 *                    bit2 : HiBeam
 *                    bit3 : LeTurn
 *                    bit4 : LoBeam
 *                    bit5 : po2
 *                    bit6 : Starry sky
 *                    bit7 : Corner
 */
#define DaytimeAndPosn_Mask 0x01u
#define Dlp_Mask            0x02u
#define HiBeam_Mask         0x04u
#define LeTurn_Mask         0x08u
#define LoBeam_Mask         0x10u
#define Po2_Mask            0x20u
#define StarrySky_Mask      0x40u
#define Corner_Mask         0x80u
typedef struct SystemSleepWeakupModel
{
    uint8_t lampsOnOffMask_;
    SystemState systemState_;
} SystemSleepWeakupModel;
extern bool IsSystemGoingToSleep();
extern bool IsSystemInIdle();
extern bool IsBothPo2AndStarrySkyTurnOff();

#endif
